/**
 * Created by yu on 16/8/23.
 */
var fs = require('fs');
var http = require('http');
var mime = require('mime');
var path = require('path');

var server = http.createServer(function(request,response){
    var url = request.url;
    if(url==='/favicon.ico') return;
    if(url==='/'){
        url = '/index.html';
    }
    //mime.lookup()得到文件的content-Type
    response.setHeader('Content-Type',mime.lookup(url)+';charset=utf-8');
    //指定文件路径设置编码,得到的data就是字符串类型的.
    fs.readFile('.'+url,'utf-8',function(err,data){
        response.write(data);
        response.end();
    })
})
server.listen('8083','localhost');